/*
Copyright 2005-2014 CP Fricano - All Rights Reserved

This software and source code is licensed under the Apache
License, Version 2.0. You may not use this software or source
code except in compliance with the License.  You may obtain a
copy of the License at: http://www.apache.org/licenses/LICENSE-2.0.
Use and distributed under this License is on an "as is" basis,
without expressed or implied warranties or conditions of any kind.
See the License for the specific language governing permissions and
limitations.
 */

package com.fricano.java42.instructional.example.thread.tester;

import java.io.PrintStream;

import com.fricano.java42.base.components.utility.impl.Utility;
import com.fricano.java42.instructional.example.thread.Monitor;
import com.fricano.java42.instructional.example.thread.Notifier_01;
import com.fricano.java42.instructional.example.thread.Waiter_01;

public class WaitNotify_Tester_01 {

    final private PrintStream out;

    public WaitNotify_Tester_01(final PrintStream out) {
        this.out = out;
    }

    public void testIt() throws Exception {

        final Monitor monitor = new Monitor();

        final Waiter_01 w = new Waiter_01(out, monitor);
        Utility.sleepMilliSeconds(42 * 42);
        w.waiter();
        Utility.sleepMilliSeconds(42 * 42);

        final Notifier_01 n = new Notifier_01(out, monitor);
        Utility.sleepMilliSeconds(42 * 42);
        n.notifier();
        Utility.sleepMilliSeconds(42 * 42);
    }

    public static void main(final String[] args) throws Exception {
        final PrintStream pStream1 = java.lang.System.out;
        final PrintStream pStream2 = java42.lang.System.out;
        final WaitNotify_Tester_01 tester = new WaitNotify_Tester_01(pStream2);
        tester.testIt();
    }

}
